package com.le.dub.conf;



import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 *
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {
    @Resource
    private AppInterceptor appInterceptor;



    @Override
    public void addInterceptors(InterceptorRegistry registry) {

         registry.addInterceptor(appInterceptor).addPathPatterns("/app/**").excludePathPatterns( "/**/*.js", "/**/*.css", "/**/*.html","/images/**"
                 ,"/css/**","/fonts/**","/favicon.ico"); //所有的请求都要拦截。



    }


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*") // 允许的域
                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的方法
                .allowedHeaders("*") // 允许的头部
                .allowCredentials(true); // 允许携带凭证

    }
}
